package com.example.brazil_project.util;

import com.example.brazil_project.function.ArriveProductInfoFunction;
import com.example.brazil_project.function.DucumentFunction;
import com.example.brazil_project.function.IndexFunction;
import com.example.brazil_project.function.LoginFunction;
import com.example.brazil_project.function.MsgFunction;
import com.example.brazil_project.function.PhotoFunction;
import com.example.brazil_project.function.PhotographArrFunction;
import com.example.brazil_project.function.Public_method;
import com.example.brazil_project.function.RedectDucumentFunction;
import com.example.brazil_project.function.SearchProductFunction;
import com.example.brazil_project.function.UpdateProfileFunction;

import android.app.Activity;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebviewSetting {

	private static WebView webview = null;
	/***
	 * 
	 * @param content 当前Activity 
	 * @param loadUrl webview 的Url ַ
	 * @return 
	 */
	public static WebView getWebview(Activity content,String loadUrl){
		webview = new WebView(content);
		
		
		 //设置JS 接口 必须放在webview最前面。。（估计避免页面加载后无法检查到方法）
	    Public_method public_method = new Public_method(content);
		webview.addJavascriptInterface(public_method , "Public_method");
	  	//照相功能
	  	webview.addJavascriptInterface(new PhotoFunction(content,webview) , "PhotoFunction"); 
	  	
	  	webview.addJavascriptInterface(new MsgFunction(content,webview),"MsgFunction"); 
	  	
	  	webview.addJavascriptInterface(new LoginFunction(content,webview) , "LoginFunction"); 
	  	
		webview.addJavascriptInterface(new IndexFunction(content,webview) , "IndexFunction"); 
		
		webview.addJavascriptInterface(new DucumentFunction(content,webview) , "DucumentFunction");
		
		webview.addJavascriptInterface(new RedectDucumentFunction(content,webview) , "RedectDucumentFunction");
		
		webview.addJavascriptInterface(new UpdateProfileFunction(content,webview) , "UpdateProfileFunction"); 
		
		webview.addJavascriptInterface(new LoginFunction(content,webview) , "LoginFunction"); 
		
		webview.addJavascriptInterface(new SearchProductFunction(content,webview) , "SearchProductFunction"); 
		
		webview.addJavascriptInterface(new ArriveProductInfoFunction(content,webview) , "ArriveProductInfoFunction"); 
		
		webview.addJavascriptInterface(new PhotographArrFunction(content,webview) , "PhotographArrFunction"); 
		
		
		
		webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); //���ù�������ʽ
	    WebSettings wv_setttig = webview.getSettings();
	    wv_setttig.setJavaScriptEnabled(true);
	
		webview.loadUrl(loadUrl);
	    webview.setLongClickable(true);  
	 

		//���title��ʾ
	    webview.setWebChromeClient(new WebChromeClient(){
			@Override
			 public void onReceivedTitle(WebView view, String title) {
				//textview.setText(title);
				 super.onReceivedTitle(view, title); 
			 };
			 
		});
		
		//�����Լ�APP����������������ϵͳĬ�������
	    webview.setWebViewClient(new WebViewClient(){
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url){
				return super.shouldOverrideUrlLoading( view,  url);
				
			}
		});
	 	wv_setttig.setCacheMode(WebSettings.LOAD_NO_CACHE);
	 
	  
	  	//不设置缓存
	  	webview.setWebViewClient(new WebViewClient() {
			  @Override
			  public void onPageFinished(WebView view, String url) {
			      super.onPageFinished(view, url);
			      //在这里执行你想调用的js函数
			      webview.loadUrl("javascript:PageFinished()");
			  }

			});

		return webview;
		
		
	}
}
